/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.eng.scc.core.schema.fetcher;

import com.eng.scc.core.data.Freight;
import com.eng.scc.core.db.Database;
import com.eng.scc.core.db.Fetcher;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author Rafael
 */
public class FreightFetcher implements Fetcher<Freight>
{
    @Override
    public Freight fetch( ResultSet ps ) throws Exception
    {
        Freight f = new Freight();
        
        f.setId( ps.getInt( 1 ) );
        f.setVehicleId( ps.getInt( 2 ) );
        f.setDriverId( ps.getInt( 3 ) );
        f.setDepartureDate( ps.getDate( 4 ) );
        f.setArrivalDate( ps.getDate( 5 ) );
        f.setComission( ps.getDouble( 6 ) );
        f.setInitKm( ps.getString( 7 ) );
        f.setEndKm( ps.getString( 8 ) );
        f.setFuelPrevision( ps.getDouble( 9 ) );
        f.setState( ps.getShort( 10 ) );
        f.setTotalFillings( ps.getDouble( 11 ) );
        
        return f;
    }

    @Override
    public void insert( Freight value, PreparedStatement ps ) throws Exception
    {
        value.setId( Database.getInstance().nextID( "core_freights" ) );
        
        ps.setInt( 1, value.getId() );
        ps.setInt( 2, value.getVehicleId() );
        ps.setInt( 3, value.getDriverId() );
        ps.setDate( 4, value.getDepartureDate() );
        ps.setDate( 5, value.getArrivalDate() );
        ps.setDouble( 6, value.getComission() );
        ps.setString( 7, value.getInitKm() );
        ps.setString( 8, value.getEndKm() );
        ps.setDouble( 9, value.getFuelPrevision() );
        ps.setShort( 10, value.getState() );
        ps.setDouble( 11, value.getTotalFillings() );
    }

    @Override
    public void update( Freight value, PreparedStatement ps ) throws Exception
    {
        ps.setInt( 1, value.getVehicleId() );
        ps.setInt( 2, value.getDriverId() );
        ps.setDate( 3, value.getDepartureDate() );
        ps.setDate( 4, value.getArrivalDate() );
        ps.setDouble( 5, value.getComission() );
        ps.setString( 6, value.getInitKm() );
        ps.setString( 7, value.getEndKm() );
        ps.setDouble( 8, value.getFuelPrevision() );
        ps.setShort( 9, value.getState() );
        ps.setDouble( 10, value.getTotalFillings() );
        ps.setInt( 11, value.getId() );
    }
    
}
